/**
 * @param {Egg.Application} app - egg application
 */
module.exports = app => {
  const {
    router,
    controller
  } = app;

  // 所有接口都使用 POST 方法
  /**人员**/
  router.post('/api/person/login', controller.person.login);
  router.post('/api/person/list', controller.person.list);
  router.post('/api/person/getById', controller.person.getById);
  router.post('/api/person/create', controller.person.create);
  router.post('/api/person/update', controller.person.update);
  router.post('/api/person/updateActived', controller.person.updateActived);
  router.post('/api/person/resetPassword', controller.person.resetPassword);
  router.post('/api/person/delete', controller.person.delete);
  router.post('/api/person/getContributionStats', controller.person.getContributionStats); // 新增统计接口 单个人员 没有用到
  router.post('/api/person/getAllContributionStats', controller.person.getAllContributionStats); // 新增统计接口 所有人员
  router.post('/api/person/changePassword', controller.person.changePassword); // 添加修改密码接口
  router.post('/api/person/getAllList', controller.person.getAllList); // 添加获取所有人员列表的接口
  router.post('/api/person/getAllListTree', controller.person.getAllListTree); // 添加获取所有人员列表的接口 树状

  /**部门**/
  router.post('/api/department/list', controller.department.list);
  router.post('/api/department/create', controller.department.create);
  router.post('/api/department/update', controller.department.update);
  router.post('/api/department/delete', controller.department.delete);

  /**项目组**/
  router.post('/api/projectGroup/list', controller.projectGroup.list);
  router.post('/api/projectGroup/getById', controller.projectGroup.getById);
  router.post('/api/projectGroup/create', controller.projectGroup.create);
  router.post('/api/projectGroup/update', controller.projectGroup.update);
  router.post('/api/projectGroup/delete', controller.projectGroup.delete);

  /**人员项目组关系**/
  router.post('/api/personProjectGroup/getGroupsByPersonId', controller.personProjectGroup.getGroupsByPersonId);
  router.post('/api/personProjectGroup/getPersonsByGroupId', controller.personProjectGroup.getPersonsByGroupId);
  router.post('/api/personProjectGroup/addPersonToGroup', controller.personProjectGroup.addPersonToGroup);
  router.post('/api/personProjectGroup/removePersonFromGroup', controller.personProjectGroup.removePersonFromGroup);

  /**评分规则**/
  router.post('/api/scoringRule/list', controller.scoringRule.list);
  router.post('/api/scoringRule/getById', controller.scoringRule.getById);
  router.post('/api/scoringRule/create', controller.scoringRule.create);
  router.post('/api/scoringRule/update', controller.scoringRule.update);
  router.post('/api/scoringRule/delete', controller.scoringRule.delete);
  router.post('/api/scoringRule/enable', controller.scoringRule.enable); // 启用规则组
  router.post('/api/scoringRule/getEnabled', controller.scoringRule.getEnabled); // 获取当前启用的规则组
  router.post('/api/scoringRule/getGroupList', controller.scoringRule.getGroupList); // 添加获取分组规则的接口

  /**投稿**/
  router.post('/api/contribution/list', controller.contribution.list);
  router.post('/api/contribution/getById', controller.contribution.getById);
  router.post('/api/contribution/create', controller.contribution.create);
  router.post('/api/contribution/update', controller.contribution.update);
  router.post('/api/contribution/delete', controller.contribution.delete);
  router.post('/api/contribution/approve', controller.contribution.approve);
  router.post('/api/contribution/score', controller.contribution.score); // 新增打分接口

  /**投稿数据**/
  router.post('/api/contributionData/getPendingDataList', controller.contributionData.getPendingDataList);
  router.post('/api/contributionData/importPlatformData', controller.contributionData.importPlatformData);
  router.post('/api/contributionData/getStatsList', controller.contributionData.getStatsList);
  router.post('/api/contributionData/getOverview', controller.contributionData.getOverview); // 新增概览统计接口

  /**统计数据**/
  // 获取投稿统计信息 根据部门
  router.post('/api/statistic/getAllContributionStatisticsByDepartment', controller.statistic.getAllContributionStatisticsByDepartment);
  // 获取投稿统计信息 根据项目组
  router.post('/api/statistic/getAllContributionStatisticsByProjectGroup', controller.statistic.getAllContributionStatisticsByProjectGroup);


  /**人员去向表**/
  router.post('/api/destination/login', controller.destination.login);
  router.post('/api/destination/getDestination', controller.destination.getDestination);
  router.post('/api/destination/handle', controller.destination.handle);
  router.post('/api/destination/getDestinationByPidAndDate', controller.destination.getDestinationByPidAndDate);
  router.post('/api/destination/getDestinationByPid', controller.destination.getDestinationByPid);
  router.post('/api/destination/getAllContributionByPid', controller.destination.getAllContributionByPid);

  /**日志**/
  router.post('/api/logs', controller.logs.getLogs);

  /**公务用车**/
  // 发起公车申请接口
  router.post('/api/vehicle-application/create', controller.vehicleApplication.createApplication);
  // 获取申请列表接口
  router.post('/api/vehicle-application/list', controller.vehicleApplication.getApplicationList);
  // 查询可用车辆信息
  router.post('/api/vehicle-application/available-vehicles', controller.vehicleApplication.getAvailableVehicles);
  // 查询可用驾驶员信息
  router.post('/api/vehicle-application/available-drivers', controller.vehicleApplication.getAvailableDrivers);
  // 根据申请单 ID 获取申请单的所有信息
  router.post('/api/vehicle-application/details', controller.vehicleApplication.getApplicationDetails);
  // 取消用车申请接口
  router.post('/api/vehicle-application/cancel', controller.vehicleApplication.cancelApplication);
  // 审核用车申请接口
  router.post('/api/vehicle-application/review', controller.vehicleApplication.reviewApplication);
  // 根据车辆 ID 获取分配给该车辆的所有申请单信息
  router.post('/api/vehicle-application/applications-by-vehicle', controller.vehicleApplication.getApplicationsByVehicleId);
  // 根据驾驶员 ID 获取分配给该驾驶员的所有申请单信息
  router.post('/api/vehicle-application/applications-by-driver', controller.vehicleApplication.getApplicationsByDriverId);
  // 根据YYYY-MM获取日常记录
  router.post('/api/vehicle/daily-records', controller.vehicleApplication.getVehicleDailyRecords);
  // 用于新增车辆每日记录
  router.post('/api/vehicle-application/create-daily-record', controller.vehicleApplication.createVehicleDailyRecord);
  // 用于编辑车辆每日记录
  router.post('/api/vehicle-application/update-daily-record', controller.vehicleApplication.updateVehicleDailyRecord);
  // 用于删除车辆每日记录
  router.post('/api/vehicle-application/delete-daily-record', controller.vehicleApplication.deleteVehicleDailyRecord);
  // 车辆数据统计
  router.post('/api/vehicle-statistics/date-range', controller.vehicleStatistics.getVehicleStatisticsByDateRange);

  /******************* a8俱乐部 *******************/
  // 获取俱乐部申请列表
  router.post('/api/club-applications/list', controller.a8.list);
  // 创建新的俱乐部申请
  router.post('/api/club-applications', controller.a8.create);
  // 更新俱乐部申请信息
  router.post('/api/club-applications/update', controller.a8.update);
  // 删除俱乐部申请记录
  router.post('/api/club-applications/delete', controller.a8.delete);

  /**审批流**/
  router.post('/api/approval/create', controller.approval.create); // 发起审批
  router.post('/api/approval/list', controller.approval.list); // 获取审批列表
  router.post('/api/approval/getById', controller.approval.getById); // 获取单个审批详情
  router.post('/api/approval/handle', controller.approval.handle); // 处理审批
  router.post('/api/approval/withdraw', controller.approval.withdraw); // 撤回审批
  router.post('/api/approval/getPendingList', controller.approval.getPendingList); // 获取待审批列表
  router.post('/api/approval/getApprovedList', controller.approval.getApprovedList); // 获取已审批列表
  router.post('/api/approval/getMyApplications', controller.approval.getMyApplications); // 获取我的申请列表
  router.post('/api/approval/updateOutput', controller.approval.updateOutput); // 更新产出记录
  router.post('/api/approval/getOutputs', controller.approval.getOutputs); // 获取审批的产出记录列表

  router.post('/api/approval/getApplicationsByPerson', controller.approval.getApplicationsByPerson); // 与我有关的审批（申请人和工作成员）
  // 审批统计接口 主页
  router.post('/api/approval/getStatistics', controller.approval.getStatistics);

  // 审批权限管理接口
  router.post('/api/approvalPermission/getPersonnelWithPermissions', controller.approvalPermission.getPersonnelWithPermissions);
  router.post('/api/approvalPermission/updatePersonApprovalPermissions', controller.approvalPermission.updatePersonApprovalPermissions);
  router.post('/api/approvalPermission/findApproversByLevelTree', controller.approvalPermission.findApproversByLevelTree);
  // 处理 404
  router.all('*', async ctx => {
    ctx.throw(404, 'Not Found');
  });
};